package dialogs;

import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Point;
import javax.swing.JPanel;
import javax.swing.JDialog;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.table.TableColumnModel;
import java.util.Enumeration;
import java.util.Properties;

public class InfoDialog extends JDialog {
	private JPanel pane = null;
	private JPanel buttonsPanel = null;
	private JScrollPane scrollPane = null;
	private JButton closeButton = null;
	private JTable table = null;
	public KeyValueTableModel tableModel = null; // @jve:decl-index=0:visual-constraint=""

	/**
	 * This is the default constructor
	 */
	public InfoDialog() {
		super();
		this.setVisible(false);
		this.setModal(true);
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(450, 375);
		this.setContentPane(getPane());
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getPane() {
		if (pane == null) {
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.gridx = 0; // Generated
			gridBagConstraints1.weighty = 0.0; // Generated
			gridBagConstraints1.weightx = 0.0; // Generated
			gridBagConstraints1.insets = new java.awt.Insets(0, 0, 5, 0); // Generated
			gridBagConstraints1.gridy = 1; // Generated
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; // Generated
			gridBagConstraints.gridy = 0; // Generated
			gridBagConstraints.ipadx = 439; // Generated
			gridBagConstraints.ipady = 320; // Generated
			gridBagConstraints.weightx = 10.0; // Generated
			gridBagConstraints.weighty = 10.0; // Generated
			gridBagConstraints.insets = new java.awt.Insets(12, 12, 5, 11); // Generated
			gridBagConstraints.gridx = 0; // Generated
			pane = new JPanel();
			pane.setLayout(new GridBagLayout()); // Generated
			pane.add(getScrollPane(), gridBagConstraints); // Generated
			pane.add(getButtonsPanel(), gridBagConstraints1); // Generated
		}
		return pane;
	}

	/**
	 * This method initializes scrollPane
	 * 
	 * @return javax.swing.JScrollPane
	 */
	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setViewportView(getTable()); // Generated
		}
		return scrollPane;
	}

	/**
	 * This method initializes table
	 * 
	 * @return javax.swing.JTable
	 */
	private JTable getTable() {
		if (table == null) {
			table = new JTable();
			table.setModel(getTableModel()); // Generated
			table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
			this.setTableColumnWidth(135, 320);
		}
		return table;
	}

	/**
	 * This method initializes topicTableModel
	 * 
	 * @return dialogs.KeyValueTableModel
	 */
	private KeyValueTableModel getTableModel() {
		if (tableModel == null) {
			tableModel = new KeyValueTableModel();
		}
		return tableModel;
	}

	/**
	 * This method initializes buttonsPanel
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getButtonsPanel() {
		if (buttonsPanel == null) {
			buttonsPanel = new JPanel();
			buttonsPanel.add(getCloseButton(), null); // Generated
		}
		return buttonsPanel;
	}

	/**
	 * This method initializes closeButton
	 * 
	 * @return javax.swing.JButton
	 */
	private JButton getCloseButton() {
		if (closeButton == null) {
			closeButton = new JButton();
			closeButton.setText("Close"); // Generated
			closeButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					InfoDialog.this.setVisible(false);
				}
			});
		}
		return closeButton;
	}

	public void resizeToOriginalSize() {
		this.setSize(450, 375);
	}

	public void setTableColumnWidth(int column0, int column1) {
		TableColumnModel model = this.table.getColumnModel();
		model.getColumn(0).setPreferredWidth(column0);
		model.getColumn(1).setPreferredWidth(column1);
	}

	public void showDBMSInformation(Point loc, Dimension size) {
		loc.x += (size.getWidth() - this.getWidth()) / 2;
		loc.y += (size.getHeight() - this.getHeight()) / 2;
		this.setLocation(loc);
		this.setSize(450, 375);
		this.setTitle("DBMS Information");
		this.setTableColumnWidth(235, 175);
		this.tableModel.fireTableDataChanged();
		this.setVisible(true);
	}

	public void showSystemInformation(Point loc, Dimension size) {
		loc.x += (size.getWidth() - this.getWidth()) / 2;
		loc.y += (size.getHeight() - this.getHeight()) / 2;
		this.setLocation(loc);
		this.setSize(450, 375);
		this.setTitle("System Information");
		this.tableModel.data.clear();
		Properties properties = System.getProperties();
		Enumeration e = properties.propertyNames();
		String key = null, value = null;
		while (e.hasMoreElements()) {
			key = (String) e.nextElement();
			value = properties.getProperty(key);
			this.tableModel.data.add(new Info(key, value));
		}
		this.setTableColumnWidth(135, 320);
		this.tableModel.fireTableDataChanged();
		this.setVisible(true);
	}
}
